#include "StdAfx.h"

#include "ControlStatus.h"

ControlStatus::ControlStatus(void)
{
	
}

ControlStatus::~ControlStatus(void)
{
	for(std::map<std::string,BoundKeyStruct*>::iterator i=keyMap.begin(); i!=keyMap.end(); i++)
	{
		delete (*i).second;
	}

}


void ControlStatus::updateStatus(UltimateInputSubsystem::UltimateInputStruct * input)
{
	inputStruct = input;
}

bool ControlStatus::getKeyPressed(int index)
{
	
	return (inputStruct->pressedButtons.find(index)!= inputStruct->pressedButtons.end());
}


int ControlStatus::getKeyValue(std::string key)
{
	return inputStruct->inputMap[key];
}

void ControlStatus::bindKey(std::string abstractKey,std::string realKey)
{
	BoundKeyStruct* boundKeyStruct = new BoundKeyStruct();
	boundKeyStruct->isButton=false;
	boundKeyStruct->stringKey=realKey;

	keyMap[abstractKey] = boundKeyStruct;
}

void ControlStatus::bindKey(std::string abstractKey,int realKey)
{
	BoundKeyStruct* boundKeyStruct = new BoundKeyStruct();
	boundKeyStruct->isButton=true;
	boundKeyStruct->intKey=realKey;

	keyMap[abstractKey] = boundKeyStruct;
}

int ControlStatus::getBoundKeyValue(std::string key)
{
	if(keyMap.find(key)==keyMap.end())
	{
		return 0;
	}

	BoundKeyStruct* boundKeyStruct = keyMap[key];
	if(boundKeyStruct->isButton) 
	{
		return getKeyPressed(boundKeyStruct->intKey);

	}
	else 
	{
		return getKeyValue(boundKeyStruct->stringKey);
	}

	return 0;
}

